<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: QYoung
  Date: 2021/7/14
  Time: 21:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>显示用户信息</title>
    <script src="js/jquery-1.11.1.js"></script>
    <script src="js/bootstrap.js"></script>
    <link rel="stylesheet" href="css/bootstrap.css"/>
</head>
<body>
<%--<table border="1" width="600px" >
    <tr>
        <td>id</td>
        <td>用户名</td>
        <td>手机号码</td>
    </tr>
    <c:forEach items="${users}" var="user">
        <tr>
            <td>${user.id}</td>
            <td>${user.username}</td>
            <td>${user.telephone}</td>
        </tr>
    </c:forEach>
</table>--%>
<form action="testJSONServlet" method="post">
    用户id：<input type="text" name="userId" id="userId"><br><br>
    用户名：<input type="text" name="name" id="name"><br><br>
    密码：<input type="text" name="pass" id="pass"><br><br>
    电话号码:<input type="text" name="telephone" id="telephone">
</form>
</body>
</html>
<script>
    $(function () {
        $("#userId").blur(function () {
            var uid = $(this).val();
            /*$.post("/testJSONServlet","userId="+uid,function (rs) {
                rs = eval("("+rs+")");
                $("#name").val(rs.username);
                $("#pass").val(rs.password);
                $("#telephone").val(rs.telephone);
            })*/
            $.ajax({
                url:"testJSONServlet",
                type:"post",
                data:{"userId":uid},
                dataType:"json",
                success:function (rs) {
                    $("#name").val(rs.username);
                    $("#pass").val(rs.password);
                    $("#telephone").val(rs.telephone);
                }
            })
        })
    })
</script>
